package pe.edu.ups.studio.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pe.edu.upc.studio.excepcion.DAOExcepcion;
import pe.edu.upc.studio.negocio.GestionSalaNegocio;

/**
 * Servlet implementation class SalaServlet
 */
@WebServlet("/SalaServlet")
public class SalaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public SalaServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String strNombreSala = request.getParameter("txtNombreSala");
		String strLocal = request.getParameter("txtLocal");
		String strDireccion = request.getParameter("txtDireccion");
		int intCapacidad = Integer.parseInt(request
				.getParameter("txtCapacidad"));
		String strDet = request.getParameter("txtCaractertistica");

		GestionSalaNegocio objNeg = new GestionSalaNegocio();
		try {
			objNeg.insertarSala(strNombreSala, strLocal, strDireccion,
					intCapacidad, strDet);
			
			String msj="Sala registrado correctamente";
			response.sendRedirect("registrosala.jsp?mensaje="+ msj);
			
		} catch (DAOExcepcion e) {
			String msj = "No se pudo registrar";
			System.err.println(msj);
			RequestDispatcher rd = request
					.getRequestDispatcher("/error.jsp?error=" + msj);
			rd.forward(request, response);
		}
	}

}
